package com.example.its2021606134chh.DAModule;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.Toast;

import com.example.its2021606134chh.R;
//import com.haibin.calendarview.CalendarView;
import android.widget.CalendarView;

public class DateActivity extends AppCompatActivity {

    private CalendarView calendarView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_date);
        calendarView = findViewById(R.id.calendarView);
        calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
            @Override
            public void onSelectedDayChange(@NonNull CalendarView view, int year, int month, int dayOfMonth) {
                String content;
                if (month < 10) {
                    if (dayOfMonth < 10) {
                        content = year+"-0"+(month+1)+"-0"+dayOfMonth;
                    } else {
                         content = year+"-0"+(month+1)+"-"+dayOfMonth;
                    }
                } else {
                    if (dayOfMonth < 10) {
                         content = year+"-"+(month+1)+"-0"+dayOfMonth;
                    } else {
                        content = year+"-"+(month+1)+"-"+dayOfMonth;
                    }
                }
                Toast.makeText(DateActivity.this, "你选择了:\n"+content, Toast.LENGTH_SHORT).show();
            }
        });
    }
}